/*
 * Flashlib - QB9 common Flash library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.qb9.flashlib.screens
{
	import com.qb9.flashlib.display.QSprite;
	import com.qb9.flashlib.fsm.StateEvent;
	import com.qb9.flashlib.tasks.TaskRunner;
	
	import flash.display.*;
	
	/**
	 * Includes all features provided by <code>QSprite</code>, plus a <code>TaskRunner</code> instance.
	 *
	 * @see "examples/screenManager/ScreenManagerExample.as"
	 */
	public class Screen extends QSprite
	{
		public var tasks:TaskRunner;

		/**
		 * Create a Screen instance.
		 *
		 * @param autoStart If set to false, you will need to call <code>tasks.start()</code> manually.
		 */
		public function Screen(autoStart:Boolean = true)
		{
			tasks = new TaskRunner(this);
			if (autoStart)
				tasks.start();
				
			addEventListener(StateEvent.ENTER,enter);
			addEventListener(StateEvent.EXIT,exit);
		}
		
		protected function enter(e:StateEvent):void
		{
		}
		
		protected function exit(e:StateEvent):void
		{
		}

		/** Remove the Screen instance from the display list and dispose all running tasks. */
		public override function dispose():void
		{
			tasks.dispose();
			removeEventListener(StateEvent.ENTER,enter);
			removeEventListener(StateEvent.EXIT,exit);
			super.dispose();
		}
	}
}


